/*
 * Copyright 2014 Semidata. All rights reserved.
 */
package com.semidata.rtd.core.datasource.redis;

import java.util.concurrent.TimeUnit;

import com.semidata.rtd.core.datasource.DataSourceService;
import com.semidata.rtd.core.redis.RedisClient;

/**
 * @author shewei@semidata.com, She Wei
 *
 */
public class RedisDataSourceService implements DataSourceService<RedisDataSource> {

	
	private static final long KEEP_ALIVE_TIME = 10;
    private static final TimeUnit TIME_UNIT = TimeUnit.SECONDS;
    private static final int CORE_POOL_SIZE =  Runtime.getRuntime()
	        .availableProcessors();
    private static final int MAX_POOL_SIZE =  Runtime.getRuntime()
	        .availableProcessors();
    
	private RedisDataSource datasource;
	private String[] hosts;
	private int threadNum;
	private int connectionNum;
	private int timeout;
	
	public RedisDataSourceService(String[] hosts, int threadNum, int connectionNum, int timeout) {
		this.hosts = hosts;
		this.threadNum = threadNum;
		this.connectionNum = connectionNum;
		this.timeout = timeout;
	}
	
    @Override
    public void start() {
    	
    	datasource = new RedisDataSource(hosts, threadNum, connectionNum, timeout);
    }

	
    @Override
    public void stop() {
    	RedisClient client = datasource.getClient();
    	
    	if (client != null) {
    		client.stop();
    	}
    	
    }

	
    @Override
    public RedisDataSource getDataSource() {
	    return datasource;
    }

}
